package mspbots.hubspot.data.core.contacts;

import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.r2dbc.repository.R2dbcRepository;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * mspbots.data.sync.autotask.badmessage.AtBadMsgRepository
 *
 * @author <a href="https://github.com/vnobo">Alex bob</a>
 * @date Created by 2020/7/21
 */
@Repository
public interface ContactsRepository extends R2dbcRepository<Contact, Long> {

    /**
     * find entity other id and tenant id
     *
     * @param otherId  other Id
     * @param tenantId tenant id
     * @return account entity
     */
    Mono<Contact> findByOtherIdAndTenantId(Long otherId, Long tenantId);

    /**
     * find entity tenant id
     *
     * @param tenantId tenant id
     * @param emails   emails id
     * @return account entity
     */
    @Query("select * from hubspot_contacts where tenant_id=:tenantId and lower(email) in (:emails) ")
    Flux<Contact> findByEmails(Long tenantId, List<String> emails);
}
